<template>
<!-- 库存发生明细 -->
    <div class="app-container">
    <el-row :gutter="20">
        <el-col :span="24" :xs="24">
        <el-form  :inline="true"
                    ref="queryRef"
                    :model="queryParams"
                    label-width="100px">
            <el-form-item label="货品编号" prop="productCode">
                <el-input
                    v-model="queryParams.productCode"
                    placeholder="请输入货品编号"
                    clearable
                    style="width: 180px;"
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="货品名称" prop="productName">
                <el-input
                    v-model="queryParams.productName"
                    placeholder="请输入货品名称"
                    clearable
                    style="width: 180px;"
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="货品类型" prop="productType">
                <el-tree-select
                    style="width: 180px;"
                    v-model="form.productType"
                    :data="typeOptions"
                    :props="{ value: 'id', label: 'label', children: 'children' }"
                    value-key="id"
                    placeholder="请选择货品类型"
                    clearable
                    check-strictly
                />
            </el-form-item>
            <el-form-item label="商品规格" prop="productSpecifications">
                <el-input
                    v-model="queryParams.productSpecifications"
                    placeholder="请输入商品规格"
                    clearable
                    style="width: 180px;"
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="仓库" prop="warehousingId">
            <el-select style="width: 180px;" v-model="queryParams.warehousingId" placeholder="请选择">
                <el-option
                    v-for="item in warehouseOptions"
                    :key="item.warehouseId"
                    :label="item.warehouseName"
                    :value="item.warehouseId"
                ></el-option>
            </el-select>
            </el-form-item>
            <el-form-item>
                <el-button
                    type="primary"
                    icon="Search"
                    @click="handleQuery"
                    v-hasPermi="['system:purchase:PurchaseOrderQuery']"
                >查询</el-button>
                <el-button
                    icon="Refresh"
                    @click="resetQuery"
                >重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
        <el-col :span="22">
            <span>查询结果</span>
        </el-col>
        <el-col :span="1.5">
            <el-button
            type="danger"
            plain
            icon="Download"
            @click="handleDetailExport"
            v-hasPermi="['system:purchase:purchaseDetailOrderExport']"
            >导出</el-button>
        </el-col>
        </el-row>

        <el-table
        border
        show-summary
        v-loading="loading"
        :data="detailReceiptList">
            <el-table-column label="序号" align="center" type="index" width="60" />
            <el-table-column label="仓库" align="center" prop="warehouse.warehouseName"/>
            <el-table-column label="货品编号" align="center" prop="product.productCode"/>
            <el-table-column label="货品名称" align="center" prop="product.productName"/>
            <el-table-column label="货品类型" align="center" prop="type.productTypeName"/>
            <el-table-column label="规格" align="center" prop="product.productSpecifications"/>
            <el-table-column label="单位" align="center" prop="product.measureUnit"/>
            <el-table-column label="数量" align="center" prop="planQuantity"/>
            <el-table-column label="单价" align="center" prop="univalence"/>
            <el-table-column label="折扣" align="center" prop="discount"/>
            <el-table-column label="金额" align="center" prop="money"/>


        </el-table>
        <!-- 分页组件 -->
        <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
        />
        </el-col>
    </el-row>
    </div>
</template>

<script setup name="InventoryOccurrenceDetails">
import { useRouter } from 'vue-router';
import { listWarehouse } from '@/api/basedate/warehouse';
import { selectInventoryProduct } from '@/api/system/inventory';
import { productTypeTreeSelect } from "@/api/basedate/product";

const { proxy } = getCurrentInstance();

// 查询结果表
const detailReceiptList = ref([]);
const warehouseOptions = ref(undefined);
// 加载
const loading = ref(true);
// 总条数
const total = ref(0);
// 窗口标题
const title = ref("");
// 数据范围
const dateRange = ref([]);
// 打印类型
const printFlag = ref(false);
const router = useRouter();
const typeOptions = ref(undefined);

const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        productCode: undefined,
        productName: undefined,
        productType: undefined,
        productSpecifications: undefined,
        warehouseId: undefined,
    },
    rules: {},
});

const { queryParams, form, rules } = toRefs(data);

function Options() {
    listWarehouse().then(response => {
        warehouseOptions.value = response.rows;
    });
    productTypeTreeSelect().then(response => {
      typeOptions.value = response.data;
   });
};
/** 查询库存明细列表 */
function getList() {
    loading.value = true;
    selectInventoryProduct(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
    detailReceiptList.value = response.rows;
    total.value = response.total;
    loading.value = false;
    });
};
/** 查询按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
};
/** 重置按钮操作 */
function resetQuery() {
    typeOptions.value = undefined;
    dateRange.value = [];
    proxy.resetForm("queryRef");
    handleQuery();
    reset();
};
/** 重置操作表单 */
function reset() {
    form.value = {
        productCode: undefined,
        productName: undefined,
        productType: undefined,
        productSpecifications: undefined,
        warehouseId: undefined,
    };
    proxy.resetForm("queryRef");
};
/** 明细导出按钮操作 */
function handleDetailExport() {
    proxy.download("system/sales/salesDetailOrderExport", {
    ...queryParams.value,
    }, `库存货品表_${new Date().getTime()}.xlsx`);
};
getList();
Options();
</script>